package test1;

import test1.pojo.genericsDO.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 泛型
 */
public class GenericsTest {

    public static void main(String[] args) {
        //1、基本用法
        //没使用泛型时
//        nonUseGenerics();
        //使用泛型
//        useGenerics();

        //2、进阶
        //2.1 泛型多参数
//        MultiParamPrinter<String, Integer> multiParamPrinter = new MultiParamPrinter<>("hello", 1234);
//        multiParamPrinter.print();
        //2.2、控制泛型只能是某个类型或类型的子类
//        CarPrinter<XiaoPengCar> xiaoPengCarPrinter = new CarPrinter<>(new XiaoPengCar("小鹏"));
//        xiaoPengCarPrinter.print();

        //2.3方法使用泛型
//        printTest1(1);
//        printTest1("123");
//        printTest1(1L);

        //2.4通配符的使用
        List<Car> carList = new ArrayList<>();
        carList.add(new XiaoMiCar("xiaomi"));
        printTest6(carList);

//        List<XiaoPengCar> xiaoPengCars = new ArrayList<>();
//        xiaoPengCars.add(new XiaoPengCar("xiaopeng"));
//        printTest7(xiaoPengCars);




    }

    private static void nonUseGenerics() {
        IntegerPrinter integerPrinter = new IntegerPrinter(1234);
        integerPrinter.print();
        System.out.println("----------------");
        StringPrinter stringPrinter = new StringPrinter("1234");
        stringPrinter.print();
        System.out.println("----------------");
    }

    private static void useGenerics() {
        Printer<Integer> integerPrinter = new Printer<>(1234);
        integerPrinter.print();

        Printer<String> stringPrinter = new Printer<>("hello world");
        stringPrinter.print();
    }

    private static <T> void printTest1(T content){
        System.out.println(content);
    }

    private static <T, K> void printTest1(T content1, K content2) {
        System.out.println(content1);
        System.out.println(content2);
    }

    private static <T extends Car> void printTest1(T content1) {
        System.out.println(content1);
    }

    private static <T extends Car & Thing> void printTest2(T content1) {
        System.out.println(content1);
    }


    private static void printTest6(List<? extends Car> list){
        System.out.println(list);
    }

    private static void printTest7(List<? super XiaoMiCar> list){
        System.out.println(list);
    }
}
